import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:lucky_guy/global.dart';
import 'package:lucky_guy/main_manager.dart';
import 'package:lucky_guy/page/edit.dart';
import 'package:lucky_guy/page/random.dart';
import 'package:provider/provider.dart';

class IndexPage extends StatefulWidget {
  IndexPage({Key key}) : super(key: key);
  @override
  _IndexPageState createState() => _IndexPageState();
}

class _IndexPageState extends State<IndexPage> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    MainManager _mainManager = Provider.of<MainManager>(context);
    return FlutterEasyLoading(
      child: Container(
        padding: EdgeInsets.all(20),
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height,
        decoration: BoxDecoration(
          color: Global.backgroundColor,
          gradient: LinearGradient(
            begin: Alignment.topLeft,
            end: Alignment.bottomRight,
            colors: [
              Color(0xFF919191),
              Color(0xFFE8E7ED),
            ],
          ),
        ),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Center(
              child: Container(
                width: 250,
                height: 250,
                decoration: BoxDecoration(
                  image: DecorationImage(
                    image: AssetImage("assets/images/xiao.png"),
                    repeat: ImageRepeat.repeat,
                    fit: BoxFit.fill,
                  ),
                ),
              ),
            ),
            SizedBox(height: 10),
            Text(
              '还在为寒冷的冬天，寝室里为儿子们不愿出门拿外卖而发愁吗？',
              style: TextStyle(
                color: Global.backgroundColor,
                fontSize: 13,
                fontWeight: FontWeight.w400,
              ),
            ),
            SizedBox(height: 10),
            Text(
              '还在为争抢父亲的名头而骨肉相残，大打出手吗？',
              style: TextStyle(
                color: Global.backgroundColor,
                fontSize: 13,
                fontWeight: FontWeight.w400,
              ),
            ),
            SizedBox(height: 10),
            Row(
              children: [
                Text(
                  '让他们感受',
                  style: TextStyle(
                    color: Global.backgroundColor,
                    fontSize: 13,
                    fontWeight: FontWeight.w400,
                  ),
                ),
                Text(
                  '父爱！',
                  style: TextStyle(
                    color: Color(0xFF060606),
                    fontSize: 17,
                    fontWeight: FontWeight.w600,
                  ),
                ),
              ],
            ),
            Row(
              children: [
                Text(
                  '让命运决定谁是真正的',
                  style: TextStyle(
                    color: Global.backgroundColor,
                    fontSize: 13,
                    fontWeight: FontWeight.w400,
                  ),
                ),
                Text(
                  '父亲吧！',
                  style: TextStyle(
                    color: Color(0xFF000000),
                    fontSize: 20,
                    fontWeight: FontWeight.w600,
                  ),
                ),
              ],
            ),
            SizedBox(height: 50),
            InkWell(
              onTap: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => EditPage(),
                  ),
                );
              },
              child: Container(
                padding: EdgeInsets.fromLTRB(45, 15, 45, 15),
                decoration: BoxDecoration(
                  gradient: LinearGradient(
                    begin: Alignment.topLeft,
                    end: Alignment.bottomRight,
                    colors: [
                      Color(0xFF171618),
                      Color(0xFF3C3A3F),
                    ],
                  ),
                  borderRadius: BorderRadius.circular(10),
                ),
                child: Center(
                  child: Text(
                    '编辑候选人',
                    style: TextStyle(
                      color: Global.backgroundColor,
                      fontSize: 17,
                      fontWeight: FontWeight.w600,
                    ),
                  ),
                ),
              ),
            ),
            SizedBox(height: 30),
            InkWell(
              onTap: () {
                if (_mainManager.allLuckyGuys.length < 2) {
                  EasyLoading.showToast('请添加至少两个候选人后开始');
                } else {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) => RandomPage(),
                    ),
                  );
                }
              },
              child: Container(
                padding: EdgeInsets.fromLTRB(45, 15, 45, 15),
                decoration: BoxDecoration(
                  gradient: LinearGradient(
                    begin: Alignment.topLeft,
                    end: Alignment.bottomRight,
                    colors: [
                      Color(0xFF171618),
                      Color(0xFF3C3A3F),
                    ],
                  ),
                  borderRadius: BorderRadius.circular(10),
                ),
                child: Center(
                  child: Text(
                    '开始',
                    style: TextStyle(
                      color: Global.backgroundColor,
                      fontSize: 17,
                      fontWeight: FontWeight.w600,
                    ),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
